package cn.edu.ctbu.lab.dao;

import cn.edu.ctbu.lab.domain.Course;
import cn.edu.ctbu.lab.domain.Student;
import cn.edu.ctbu.lab.vo.CourseExt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CourseRepository extends JpaRepository<Course,Integer> {


    @Query(value="SELECT\n" +
            "\tc.id,\n" +
            "\tc.teacher_id as teacherId,\n" +
            "\tc.course_name as courseName,\n" +
            "\tt. name AS teacherName\n" +
            "FROM\n" +
            "\ttb_course c\n" +
            "LEFT JOIN tb_teacher t ON c.teacher_id = t.id limit :start ,:pageSize",nativeQuery = true)
    public List<CourseExt> getByPage(Integer start,Integer pageSize);

    @Query(value = "SELECT count(*)" +
            "FROM\n" +
            "\ttb_course c\n" +
            "LEFT JOIN tb_teacher t ON c.teacher_id = t.id ",nativeQuery = true)
    public Integer getByPageCount();

}
